<?php 
	$table = $this->table;
	$search_mode = $this->search_mode;
?>

<?php if(!$search_mode):?>
<section class="grid_12">
	<!-- 検索フォーム -->
	<div class="block-border" style="margin-bottom: 20px;">
    	<div class="block-content">
	        <h1>検索</h1>
	       <form method="post" class="form" action="/admin/room" id="search_form">
	        	<p>
        			<label for="search_type" class="inline">検索タイプ</label>
		        	<select id="search_type" name="search_type">
		        		<option value="all">全部</option>
		        		<option value="code">コード</option>
		        		<option value="description">概要</option>
		        	</select>
		        	
		        	<label for="search_type" class="inline">検索キー</label>
		        	<?php echo $this->formText("search_key")?>
		        </p>
		        
		        <p>
        			<label for="type" class="inline">会議室タイプ</label>
		        	<?php echo $this->formSelect("type", NULL, NULL, $this->room_type_list)?>
		        	
		        	<label for="number_seat" class="inline">席の数</label>
		        	<?php echo $this->formSelect("number_seat", NULL, NULL, $this->number_seat_list)?>
		        	
		        	<button type="submit" id="save_btn">検索</button>
		        </p>
	        </form>
    	</div>
	</div>

	<!-- 一覧 -->
	<div id="table_container">
		<?php echo $this->partial("/component/table.phtml", array('table'=>$table,'table_translate'=>$this->table_translate))?>
	</div>
	
	<?php echo $this->formHidden("msg", $this->msg);?>
</section>

<?php else :?>
	<?php echo $this->partial("/component/table.phtml", array('table'=>$table,'table_translate'=>$this->table_translate))?>
<?php endif;?>


<?php if(!$search_mode):?>
<!-- Table script -->
<script type="text/javascript" src="/js/table.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#number_seat").change(function(){
			refreshTable();
			return false;
		});

		$("#type").change(function(){
			refreshTable();
			return false;
		});
		
		$("#search_form").submit(function(){
			refreshTable();
			return false;
		});

		if($("#msg").val() != null && $("#msg").val() != ''){
			notify($("#msg").val());
		}
	});	

	/** AJAXを使ってテーブルのデータをリロードする*/
	function refreshTable(){
		var ajax_url = "/admin/room/index";
		
		var datas = "search_type=" + $("#search_type").val();
		datas += "&search_key=" + $.trim($("#search_key").val());
		datas += "&line_per_page=" + $("#line_per_page").val();
		datas += "&page=" + $("#page").val();
		datas += "&search=1";

		if($("#number_seat").val() != "" && $("#number_seat").val() != undefined)
			datas += "&number_seat=" + $("#number_seat").val();
		
		if($("#type").val() != "" && $("#type").val() != undefined)
			datas += "&type=" + $("#type").val();
		
		$(".black-cell span").attr('class','loading');
		jQuery.ajax({
			  url: ajax_url,
			  type: "POST",
			  data: datas,
			  success: function(data) {
				  $("#table_container").html(data);
			  },
			  complete: function(){	
				   $(".black-cell span").attr('class','success');
			  },
			  error: function() {
				  alert("Have error when loading data from server");
			  }
		});
	}
</script>
<?php endif;?>
